/**
 * Created by YAAP on 2017/8/2.
 */
define(['batch-building','batch-house'],function (BatchBuilding,BatchHouse) {
    var template=
        `
                                <div class="houseNumTab2">
                                    <div class="table-wrap">
                                        <table class="table-wrap-content" border="0">
                                            <tr>
                                                <th>楼栋号</th>
                                                <th>单元</th>
                                                <th>层数</th>
                                                <th>梯户</th>
                                                <th>房号</th>
                                            </tr>
                                            <tr class="newAddRow" v-for="item in buildingUnitList">
                                                <td class="clearfix">
                                                    <p class="left">
                                                        <Checkbox></Checkbox>
                                                    </p>
                                                    <input type="text" v-model=item.BuildingName class="inputTxt" id="num1"/>
                                                </td>
                                                <td>
                                                    <input type="text" v-model="item.UnitName" class="inputTxtShort"/>
                                                </td>
                                                <td>
                                                    <input type="text"  v-model="item.Floor"class="inputTxtShort"/>
                                                </td>
                                                <td>
                                                    <input type="text"  v-model="item.LadderAmount"class="inputTxtShort"/>
                                                </td>
                                                <td>
                                                    <input type="text" v-model="item.RoomNo" class="inputTxtShort"/>
                                                </td>
                                            </tr>

                                            <tr>
                                                <td>
                                                    <span class="addIcon">+</span>
                                                </td>
                                                <td></td>
                                                <td></td>
                                                <td></td>
                                                <td class="pr">
                                                    <button class="sureAddBtn" id="sureAddBtn">确认新增</button>
                                                </td>
                                            </tr>

                                        </table>
                                    </div>
                                      <div class="houseNumBtnAll">
                                    <button>刷新楼栋</button>
                                    <button @click="addBuilding">新增楼栋</button>
                                    <button>修改楼栋</button>
                                    <button @click="deleteBuilding">删除楼栋</button>
                                    <batch-building></batch-building>
                                    <batch-house></batch-house>

                            </div>
                                </div>



        `;

    var HousenoList={
        name:"houseno-list",
        template:template,
        components:{
            BatchBuilding,
            BatchHouse
        },
        data:function(){
            return {
                buildingUnitList:
                    [
                        {buildingno:1,unitno:1,totalfloor:12,totalladder:2,houseno:"001"}
                    ]

            }
        },
        methods:
        {
            addBuilding:function(){},
            deleteBuilding:function(){},
            getbuildingList:function(){

            }
        },

        created:function(){
            var that=this;
            window.bus.$on("batchBuidingCreated",function(buildingList)
            {
               buildingList.forEach(function(item){

                   for(var i=1;i<=item.UnitAmountPerBuilding;i++)
                   {
                   if(that.buildingUnitList.filter(b=>(b.BuildingName===item.BuildingName&&b.UnitName===i)).length==0)
                   {
                       that.buildingUnitList.push(
                           {
                               "BuildingName":item.BuildingName,
                               "UnitName":i,
                               "Floor":item.FloorAmount,
                               "LadderAmount":item.LadderAmount,

                           }
                       );
                   }
                   }
               })
            });
            window.bus.$on("editblock",function(block){
                // wwaiting for new design of batch houselist
                // $.get(window.config.UrlGetBuildingList()+block.id,function(result){
                //     if(result.IsSuccess)
                //     {
                //         that.buildingUnitList=result.ResultObject;
                //     }
                //     else
                //     {
                //         that.$Message.error("fail");
                //     }
                // })
            })
        }

    }
    return HousenoList
})
